/**
 * <p>Title: Scoring.java</p>
 * <p>Description: CS 343 Final Project. This class will incorporate scoring into the game</p>
 * @author Tim Olmstead, Brady Fetting, Erik Brown, Thales Kirk
 * @email timothy.olmstead@my.uwrf.edu, brady.fetting@my.uwrf.edu, 
 * 			erik.brown@my.uwrf.edu, thales.kirk@my.uwrf.edu
 * @date November 15, 2013
 */

package Components;


public class Scoring implements Runnable {

	long finalScore = 0;
	private boolean suspended = false;
	private boolean endThread = false;
	// placeholder score
	private static long incrementScore = 1;
	private long time = System.currentTimeMillis();
	private int difficulty = 2;
	private long count = 1;
	private int scoreSpeed = 500;

	/**
	 * @param none
	 * @description gets the difficulty
	 */
	public int getDifficulty() {
		return difficulty;
	}

	/**
	 * @param difficulty
	 * @description sets the difficulty of the game
	 */
	public void setDifficulty(int difficulty) {
		this.difficulty = difficulty;
	}

	/**
	 * @description resets the score when called, after setting the final score
	 */
	public void resetScore() {
		setFinalScore(incrementScore);
		count = 1;
		incrementScore = 1;
	}

	// Getters and setters for finalScore
	/**
	 * @param none
	 * @description gets the final score
	 */
	public long getFinalScore() {
		return finalScore;
	}

	/**
	 * @param curentScore
	 * @description sets the current score
	 */
	public void setFinalScore(long curentScore) {
		this.finalScore = curentScore;
	}

	// _______________________________________

	// Getters and setters for incrementScore
	/**
	 * @param none
	 * @description gets the incrementScore
	 */
	public static long getIncrementScore() {
		return incrementScore;
	}

	/**
	 * @description keeps track of the score. Continually increments the score
	 *              and gradually increases the rate of increase
	 */
	public void scoring() {

		try {
			Thread.sleep(100);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		long currentTime = System.currentTimeMillis();
		long temp = currentTime - time;

		// Increments score by the current count + the choice difficulty
		if (difficulty >= 0 && difficulty <= 5) {
			incrementScore += (count + difficulty);
		}
		// Increments the counter after a set period to keep the points rising
		// faster as time moves on.
		if (incrementScore % scoreSpeed == 0)
			count++;

		time = currentTime + temp;

	}

	/**
	 * @description used when score thread is started to increment score
	 */
	@Override
	public void run() {
		while (true) {
			if (!suspended) {
				// This will continually increment the score based on the time.
				scoring();

			}
			try {
				Thread.sleep(1);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			if (endThread) {
				break;
			}
		}
	}

	/**
	 * @param none
	 * @description suspends the thread
	 */
	public void suspendThread() {
		suspended = true;
	}

	/**
	 * @param none
	 * @description unsuspends the thread
	 */
	public void unsuspendThread() {
		suspended = false;
	}

	/**
	 * @param none
	 * @description enables the thread
	 */
	public void enableThread() {
		endThread = false;
	}

	/**
	 * @param none
	 * @description ends the thread
	 */
	public void endThead() {
		endThread = true;
	}
}
